//
//  PopoverPresentationController.swift
//  swift_wobo
//
//  Created by yuxin on 2018/11/16.
//  Copyright © 2018 wuxiantianli. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
    }
    
    /*
     即将布局容器视图上得子视图时调用
     containerView 容器视图, 放置展现出来的视图
     presentedView 被展现的视图
     */
    override func containerViewWillLayoutSubviews() {
        coverView.frame = (presentedView?.bounds)!
        containerView?.insertSubview(coverView, at: 0)
        
        presentedView?.frame = CGRect(x: 100, y: 56, width: 200, height: 200)
    }
    
    @objc func close() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
    lazy var coverView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0, alpha: 0.2)
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(close))
        view.addGestureRecognizer(tap)
        return view
    }()
    
}
